home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / SREFPRC1.ZIP / EXTRACTB.SRF < prev    next >
Text File  |  1996-04-28  |  1KB  |  41 lines

  1. /* ----------------------------------------------------------------------- */
  2. /* EXTRACT_BLOCK
  3. .   extract a block from haystack, defined by a Labeled block,
  4. .   where the label has the form delim1 label delim2 multi-line_string delim3  xxx
  5. .   Default values of delim1={,  2=}  3={
  6. .    Note that labels must have NO embedded spaces.
  7. */
  8. /* ----------------------------------------------------------------------- */
  9.  
  10. sref_extract_block:
  11.  
  12.   parse arg haystack , alabel , delim1  , delim2  , delim3
  13.  
  14.  if delim1='' then delim1='{'
  15.  if delim2='' then delim2='}'
  16.  if delim3='' then delim3=delim1
  17.  
  18.   alabel=translate(alabel)
  19.   thaystack=translate(haystack)
  20.  
  21. /* see any alabel appears anywhere */
  22.    foo=pos(alabel,thaystack)
  23.    if foo=0 then return ""      /* no match to label name, so no label */
  24.  
  25. /* might as well use this info, it's probably very good */
  26.    foo0=lastpos(delim1,haystack,foo)  /* find potential beginning */
  27.    if foo0=0 then foo0=foo    /* false lead, but we can start from here */
  28. /* start the definitive search at this first guess */
  29.    maybe=substr(haystack,foo0)
  30.    do until maybe=""
  31.       parse var maybe e1 (delim1) labelq (delim2) maybe
  32.       labelq=strip(labelq)
  33.       if translate(labelq)=alabel then do
  34.          parse var maybe putem (delim3) .
  35.          return putem
  36.       end
  37.    end
  38.    return ""            /* if here, no match */
  39.  
  40.  
  41.